var app = getApp();
var util = require('../../../utils/util.js');
var common = require('../../../utils/common.js');
var PageBase = require('../../../common/PageBase.js');
var ajax = require('../../../utils/ajax.js');

Page(common.extendPage(PageBase, {
  data: {
    dataLoaded: false,
    currentTab: 0,
    couponList: []
  },

  onLoad(options) {
    var _self = this;
    common.initApp({
      loginSuc: () => {
        _self._getList(0);
      }
    });

  },

  /**
   * 事件切换tab
   */
  _tabSwitch: function (evt) {
    var formId = evt.detail.formId;
    var index = +evt.currentTarget.dataset.current;
    this._toTab(index);
    //common.submitForm(formId);
  },

  _toTab: function (index, cb) {
    this.setData({
      currentTab: index,
      couponList: [],
    });
    this._getList(index);
  },

	/**
	 * 获取优惠券列表
	 * @return {[type]} [description]
	 */
  _getList(index) {
    ajax.G({
      url: "m=plugins&c=coupon&a=mycoupon",
      data: {
        uid: app.getUid(),
        size: 999,
        used: index
      },
      success: (res) => {
        //debugger;
        var couponList = res.data;
        this.setData({
          dataLoaded: true,
          couponList: couponList
        });
      }
    });

  }

}));